package com.hqyj.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class UserConditional implements Condition {
// 你有没有引入fastonjson

    // public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadataannotatedTypeMetadata) {
// //怎么变得更加灵活呢？
// try {
// Class.forName("com.alibaba.fastjson.JSON");
// return true;
// } catch (ClassNotFoundException e) {
// return false;
// }
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata
            annotatedTypeMetadata) {
//怎么变得更加灵活呢？
        boolean mark = true;
        try {
            Map<String, Object> annotationAttributes =
                    annotatedTypeMetadata.getAnnotationAttributes(ConditionOnClass.class.getName());
//输出
            String[] values = (String[]) annotationAttributes.get("value");
            for (String value : values) {
                Class.forName(value);
            }
        } catch (Exception e) {
            mark = false;
        }
        return mark;
    }
}